package com.travel.controller;

import cn.hutool.core.bean.BeanUtil;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.travel.config.oss.OSSAliyunFileStorageService;
import com.travel.dto.TravelProductAddDTO;
import com.travel.dto.TravelProductPageDto;
import com.travel.dto.TravelProductUpdateDTO;
import com.travel.pojo.TravelProducts;
import com.travel.vo.ItineraryDayVo;
import com.travel.vo.PricingDetailVo;
import com.travel.vo.TravelProductBasicVo;
import com.travel.vo.TravelProductVo;
import com.travel.result.PageResult;
import com.travel.result.Result;
import com.travel.service.TravelProductService;
import com.travel.vo.TravelProductBasicVo;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @author: libin
 * Date: 2025/6/10 10:59
 * Description:
 **/
@Slf4j
@RestController
@RequestMapping("/travel/products")
public class TravelProductController {

    @Autowired
    private TravelProductService travelProductService;


    @ApiOperation("获取首数据")
    @GetMapping("/list")
    public Result<PageResult> getTravelProductList(TravelProductPageDto dto) {

        PageResult page =  travelProductService.getTravelProductList(dto);
        return Result.success(new PageResult(page.getTotal(), page.getRecords()));
    }


    @ApiOperation("获取产品基础信息 + 景点介绍")
    @GetMapping("/{productId}/basic")
    public Result<TravelProductBasicVo> getProductBasicInfo(
            @PathVariable("productId") Integer productId) {
        TravelProductBasicVo vo = travelProductService.getBasicInfoWithAttractions(productId);
        return Result.success(vo);
    }

    @ApiOperation("获取产品行程安排")
    @GetMapping("/{productId}/itineraries")
    public Result<List<ItineraryDayVo>> getProductItineraries(
            @PathVariable("productId") Integer productId) {
        List<ItineraryDayVo> voList = travelProductService.getItinerariesByDay(productId);
        return Result.success(voList);
    }

    @ApiOperation("获取产品费用说明")
    @GetMapping("/{productId}/pricing")
    public Result<List<PricingDetailVo>> getProductPricing(
            @PathVariable("productId") Integer productId) {
        List<PricingDetailVo> voList = travelProductService.getPricingDetails(productId);
        return Result.success(voList);
    }

    @ApiOperation("获取录播图展示")
    @GetMapping("/carouselImages")
    public Result<List<String>> getCarouselImages() {
        List<String> images = travelProductService.getCarouselImages();
        return Result.success(images);
    }

    @ApiOperation("新增景点")
    @PostMapping("/addTravelProduct")
    public Result<Integer> addTravelProduct(@RequestBody TravelProductAddDTO travelProductAddDTO) {
        Integer productId = travelProductService.addTravelProduct(travelProductAddDTO);
        return Result.success(productId);
    }

    @ApiOperation("修改景点")
    @PostMapping("/updateTravelProduct")
    public Result<Boolean> updateTravelProduct(@RequestBody TravelProductUpdateDTO travelProductUpdateDTO) {
        boolean result = travelProductService.updateTravelProduct(travelProductUpdateDTO);
        return Result.success(result);
    }


    @ApiOperation("删除景点")
    @DeleteMapping("/deleteTravelProduct/{productId}")
    public Result<Boolean> deleteTravelProduct(@PathVariable Integer productId) {
        boolean result = travelProductService.deleteTravelProduct(productId);
        return Result.success(result);
    }

    @ApiOperation("根据id获取景点详情")
    @GetMapping("/getTravelProductById/{productId}")
    public Result<TravelProductVo> getTravelProductById(@PathVariable Integer productId) {
        TravelProductVo result = travelProductService.getProductWithRelations(productId);
        return Result.success(result);
    }


}
